package com.zerone.aidlstudy;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.Locale;

/**
 * Created by Alex Pang on 2017/6/6.
 * Profile:
 */
public class Employee implements Parcelable {
    public static final String SEX_MALE = "M";
    public static final String  SEX_FEMALE = "F";

    public int sno;
    public String name;
    public String gender;
    public int age;
    public int salary;

    public Employee() {}
    private Employee(Parcel in) {
        readFromParcel(in);
    }

    public static final Creator<Employee> CREATOR = new Creator<Employee>() {
        @Override
        public Employee createFromParcel(Parcel in) {
            return new Employee(in);
        }

        @Override
        public Employee[] newArray(int size) {
            return new Employee[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(sno);
        dest.writeString(name);
        dest.writeString(gender);
        dest.writeInt(age);
        dest.writeInt(salary);
    }

    public void readFromParcel(Parcel in) {
        sno = in.readInt();
        name = in.readString();
        gender = in.readString();
        age = in.readInt();
        salary = in.readInt();
    }

    @Override
    public String toString() {
        return String.format(Locale.ENGLISH, "Employee[ %d, %s, %s, %d, %d ]", sno, name, gender, age, salary);
    }
}
